#include<bits/stdc++.h>
using namespace std;
namespace IO
{
	char buff[1<<21],*p1=buff,*p2=buff;
	char getch(){return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;}
	template<typename T>void read(T &x){char CH=getch();int fl=1;x=0;while(CH>'9'||CH<'0'){if(CH=='-')fl=-1;CH=getch();}while(CH<='9'&&CH>='0'){x=x*10+CH-48;CH=getch();}x*=fl;}
	template<typename T>void read_s(T &x){x="";char CH=getch();while(!(CH>='a'&&CH<='z')&&!(CH>='A'&&CH<='Z'))CH=getch();while((CH>='a'&&CH<='z')||(CH>='A'&&CH<='Z')){x+=CH;CH=getch();}}
	template<typename T,typename ...Args>void read(T &x,Args& ...args){read(x);read(args...);}
	char obuf[1<<21],*p3=obuf;
	void putch(char CH) {if(p3-obuf<(1<<21))*p3++=CH;else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=CH;}
	char CH[100];
	template<typename T>void write(T x) {if(!x)return putch('0');if(x<0)putch('-'),x*=-1;int top=0;while(x)CH[++top]=x%10+48,x/=10;while(top)putch(CH[top]),top--;}
	template<typename T,typename ...Args>void write(T x,Args ...args) {write(x);putch(' ');write(args...);}
	void put(string s){for(int i=0;i<s.size();i++)putch(s[i]);}
	void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
string s,t; 
int n,m;
int f[50005][1005];
int fail[5005],vis[5005][30];
inline int add(int p,char c)
{
	int tmp=p;
	if(vis[tmp][c-'a']!=-1) return vis[p][c-'a'];
	while(p&&t[p+1]!=c) p=fail[p];
	if(t[p+1]==c) ++p;
	return vis[tmp][c-'a']=p; 
}
int main()
{
	freopen("neck.in","r",stdin);
	freopen("neck.out","w",stdout);
	read_s(s);read_s(t);
	n=s.size();m=t.size();s=' '+s;t=' '+t;
	for(int i=2,j=0;i<=m;i++) 
	{
		while(j&&t[i]!=t[j+1]) j=fail[j];
		if(t[i]==t[j+1]) ++j;
		fail[i]=j;
	}
	memset(f,0x3f,sizeof f);
	memset(vis,-1,sizeof vis);
	f[0][0]=0;
	for(int i=1;i<=n;i++)
		for(int j=0;j<m;j++)
		{
			f[i][j]=min(f[i][j],f[i-1][j]+1);
			int nxt=add(j,s[i]);
			if(nxt!=m) f[i][nxt]=min(f[i][nxt],f[i-1][j]);
		}
	int ans=1e9;
	for(int i=0;i<m;i++) ans=min(ans,f[n][i]);
	write(n-ans); 
	flush();
	return 0;
}
